﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySql.Data.MySqlClient;
using MySql.Data.Types;
using TAMS;

namespace TAMS.Admin
{
    public partial class Admin_Course1 : System.Web.UI.Page
    {
        MySqlConnection conn;
        MySqlCommand sqlCommand;
        MySqlDataReader readVals;
        string strProvider = Resource1.databaseConnection;
        string currentYear;
        int month;
        string currentSemester;

        protected void Page_Load(object sender, EventArgs e)
        {
            ((Menu)Master.FindControl("Menu1")).Items[4].Selected = true;

             currentYear = DateTime.Now.Year.ToString();
             month = Convert.ToInt32(DateTime.Now.Month.ToString());

             currentSemester = null;

            /*Dynamic Semester Parser ::G*/
            if (month >= 1 && month <= 5)
            {
                currentSemester = "SPRING";
            }
            else if (month >= 6 && month <= 9)
            {
                currentSemester = "SUMMER";
            }
            else if (month >= 9 && month <= 12)
            {
                currentSemester = "FALL";
            }

            if (!IsPostBack)
            {
                Label1.Text = "Current Semester: " + currentSemester + " " + currentYear;


                TAMS.SelectParameters.Add("sem", currentSemester);
                TAMS.SelectParameters.Add("y", currentYear);
            }

        }

        protected void details_click(object sender, EventArgs e)
        {

            GridViewRow clickedRow = ((Button)sender).NamingContainer as GridViewRow;

            ClientScript.RegisterStartupScript(this.GetType(), "CloseWin", "<script>window.close()</script>");
            // id yi alıyor cell in 1. indexi
            string key = clickedRow.Cells[0].Text;

            string url = "../Details.aspx?type=student&id=" + key;

            ClientScript.RegisterStartupScript(this.GetType(), "OpenWin", "<script>openNewWin('" + url + "')</script>");

        }

        protected void addSection_click(object sender, EventArgs e)
        {

            GridViewRow clickedRow = ((Button)sender).NamingContainer as GridViewRow;

            ClientScript.RegisterStartupScript(this.GetType(), "CloseWin", "<script>window.close()</script>");
            // id yi alıyor cell in 1. indexi
            string key = clickedRow.Cells[0].Text;

            string url = "../addSection.aspx?year=" + currentYear + "&semester=" + currentSemester +"&cid=" +key;

            ClientScript.RegisterStartupScript(this.GetType(), "OpenWin", "<script>openNewWin('" + url + "')</script>");

        }

        protected void Button5_Click(object sender, EventArgs e)
        {
            string url = "../oldCourses.aspx?year="+ currentYear  +"&semester=" + currentSemester;

            ClientScript.RegisterStartupScript(this.GetType(), "OpenWin", "<script>openNewWin('" + url + "')</script>");
        }
    }
}